// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package resource

import (
	"strings"

	"k8s.io/apimachinery/pkg/api/errors"

	"code.geniusai.org/notebook-manager/pkg/entity"
)

func k8sErrToUI(err error) error {

	if errors.IsInvalid(err) {
		if strings.Contains(err.Error(), "metadata.name") {
			return entity.NewError(entity.CodeK8sFieldError, entity.MsgK8sNameFieldInvalid)
		}
		return entity.NewError(entity.CodeK8sFieldError, entity.MsgK8sFieldInvalid)
	}
	return err
}
